//
//  SKSwitch.m
//  SouthKoreaDoorLock
//
//  Created by Umeinfo on 2018/1/18.
//  Copyright © 2018年 andy90s. All rights reserved.
//

#import "SKSwitch.h"

@interface SKSwitch ()

@property (nonatomic, strong) UIButton *lockButton;
@property (nonatomic, strong) UIButton *unlockButton;
@property (nonatomic, strong) UIImageView *backgroundView;

@end

@implementation SKSwitch

- (instancetype)init {
    if (self = [super init]) {
        [self setupViews];
    }
    return self;
}

- (void)setupViews {
//    UIImageView *backgroundView = [UIImageView new];
//    backgroundView.image = [UIImage imageNamed:@"settingbox"];
    [self addSubview:self.backgroundView];
    [self.backgroundView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.offset(200);
        make.height.offset(30);
        make.center.equalTo(self);
    }];
    
    // lockButton & unlockButton button.
    [self addSubview:self.lockButton];
    [self addSubview:self.unlockButton];
    [self.lockButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.bottom.equalTo(self.backgroundView);
        make.width.offset(100);
    }];
    
    [self.unlockButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.top.bottom.equalTo(self.backgroundView);
        make.width.offset(100);
    }];
    
    
}

#pragma mark - Access

- (void)setBackIconName:(NSString *)backIconName {
    _backIconName = backIconName;
    self.backgroundView.image = [UIImage imageNamed:_backIconName];
}

#pragma mark - Actions

- (void)lock {
    [self.lockButton setBackgroundImage:[UIImage imageNamed:@"settingbox_check"] forState:UIControlStateNormal];
    [self.unlockButton setBackgroundImage:[UIImage imageNamed:@""] forState:UIControlStateNormal];
    
     [self.lockButton setTitle:self.titles[0] forState:UIControlStateNormal];
     [self.unlockButton setTitle:SKLANGUAGE(@"") forState:UIControlStateNormal];
}

- (void)unlock {
    [self.lockButton setBackgroundImage:[UIImage imageNamed:@""] forState:UIControlStateNormal];
    [self.unlockButton setBackgroundImage:[UIImage imageNamed:@"settingbox_check"] forState:UIControlStateNormal];
    
     [self.lockButton setTitle:SKLANGUAGE(@"") forState:UIControlStateNormal];
     [self.unlockButton setTitle:self.titles[1] forState:UIControlStateNormal];
}

#pragma mark - lazy

- (UIButton *)lockButton {
    if (!_lockButton) {
        _lockButton = [UIButton new];
        [_lockButton addTarget:self action:@selector(lock) forControlEvents:UIControlEventTouchUpInside];
    }
    return _lockButton;
}

- (UIButton *)unlockButton {
    if (!_unlockButton) {
        _unlockButton = [UIButton new];
        [_unlockButton addTarget:self action:@selector(unlock) forControlEvents:UIControlEventTouchUpInside];
    }
    return _unlockButton;
}

- (UIImageView *)backgroundView {
    if (!_backgroundView) {
        _backgroundView = [UIImageView new];
    }
    return _backgroundView;
}

@end
